<template>
    <div class="dashboard-editor-container">
        <el-row :gutter="10" class="panel-group">
            <el-col :span="8" class="card-panel-col">
                <div class="card-panel">
                    <div class="card-panel-icon-wrapper icon-people">
                        <svg-icon
                            icon-class="education"
                            class-name="card-panel-icon"
                        />
                    </div>
                    <div class="card-panel-description">
                        <div class="card-panel-text">
                            课程数量
                        </div>
                        <h4>{{ courseNum }}</h4>
                    </div>
                </div>
            </el-col>
            <el-col :span="8" class="card-panel-col">
                <div class="card-panel">
                    <div class="card-panel-icon-wrapper icon-user">
                        <svg-icon
                            icon-class="form"
                            class-name="card-panel-icon"
                        />
                    </div>
                    <div class="card-panel-description">
                        <div class="card-panel-text">
                            题目数量
                        </div>
                        <h4>{{ questionNum }}</h4>
                    </div>
                </div>
            </el-col>
            <el-col :span="8" class="card-panel-col">
                <div class="card-panel">
                    <div class="card-panel-icon-wrapper icon-money">
                        <svg-icon
                            icon-class="job"
                            class-name="card-panel-icon"
                        />
                    </div>
                    <div class="card-panel-description">
                        <div class="card-panel-text">
                            项目数量
                        </div>
                        <h4>{{ projectNum }}</h4>
                    </div>
                </div>
            </el-col>
        </el-row>
        <el-row :gutter="32">
            <el-col :span="12" class="card-box">
                <el-card>
                    <div slot="header"><span>人员培训信息</span></div>
                    <div class="chart-wrapper">
                        <pie-chart ref="userTrainInfo" />
                    </div>
                </el-card>
            </el-col>
            <el-col :span="12" class="card-box">
                <el-card>
                    <div slot="header"><span>培训信息</span></div>
                    <div class="chart-wrapper">
                        <BarChart ref="trainChart" />
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="32">
            <el-col :span="24" class="card-box">
                <el-card>
                    <div slot="header"><span>培训学时</span></div>
                    <!-- <el-date-picker
                        v-model="syncTime"
                        type="month"
                        value-format="yyyy-MM"
                        placeholder="请选择月份查询"
                        @change="this.userStatTrendList"
                        clearable
                    >
                    </el-date-picker> -->
                    <line-chart ref="trainTime" />
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import LineChart from '../../dashboard/LineChart'
import PieChart from '../../dashboard/PieChart'
import BarChart from '../../dashboard/BarChart'
import { getTrainBaseStatistics } from "@/api/system/train";
export default {
    data () {
        return {
            courseNum: 0,
            projectNum: 0,
            questionNum: 0
        }
    },
    components: {
        LineChart,
        PieChart,
        BarChart
    },
    created () {
        this.getTrainBaseStatistics()
    },
    methods: {
        getTrainBaseStatistics () {
            getTrainBaseStatistics().then(response => {
                // let userNumData = response.data.count5;
                // this.userNumX = userNumData.users;
                // this.userNumY = userNumData.days;
                // this.$nextTick(() => {
                //     this.$refs.userNum.initChart(this.userNumX, this.userNumY, '人员-数量');
                // })
                let resData = response.data
                this.courseNum = resData.courseNum
                this.projectNum = resData.projectNum
                this.questionNum = resData.questionNum
                this.$nextTick(() => {
                    let trainChartData = [resData.trainPeopleTime, resData.completeTrainPeopleTime, resData.examPeopleTime, resData.examQualifiedPeopleTime]
                    let trainChartX = ['培训人次', '完成培训人次', '考试人次', '考试合格人次']
                    this.$refs.trainChart.initChart(trainChartData, trainChartX)
                    let userTrainInfoLabel = ['已培训人数', '未培训人数']
                    let userTrainInfoData = [{
                        name: '已培训人数',
                        value: resData.trainPeopleNum
                    }, {
                        name: '未培训人数',
                        value: resData.unTrainPeopleNum
                    }]
                    this.$refs.userTrainInfo.initChart(userTrainInfoLabel, userTrainInfoData)
                    this.$refs.trainTime.initChart(resData.periods, resData.months);
                })
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;
    padding-top: 10px;
    
    height: calc(100vh - 120px);
    min-height: 100%;
    overflow-y: auto;

    .chart-wrapper {
        background: #fff;
        padding: 16px 16px 0;
        margin-bottom: 32px;
    }
}
.panel-group {
    margin-top: 18px;

    .card-panel-col {
        margin-bottom: 32px;
    }

    .card-panel {
        position: relative;
        height: 108px;
        cursor: pointer;
        font-size: 12px;
        position: relative;
        overflow: hidden;
        color: #666;
        background: #fff;
        box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
        border-color: rgba(0, 0, 0, 0.05);
        padding: 0 20px;

        &:hover {
            .card-panel-icon-wrapper {
                color: #fff;
            }

            .icon-people {
                background: #40c9c6;
            }

            .icon-user {
                background: #36a3f7;
            }

            .icon-money {
                background: #f4516c;
            }

            .icon-shopping {
                background: #34bfa3;
            }
        }

        .icon-people {
            color: #40c9c6;
        }

        .icon-user {
            color: #36a3f7;
        }

        .icon-money {
            color: #f4516c;
        }

        .icon-shopping {
            color: #34bfa3;
        }

        .card-panel-icon-wrapper {
            float: left;
            padding: 10px;
            transition: all 0.38s ease-out;
            border-radius: 6px;
            position: absolute;
            left: 20px;
            top: 50%;
            margin-top: -30px;
        }

        .card-panel-icon {
            font-size: 40px;
        }

        .card-panel-description {
            float: right;
            font-weight: bold;
            margin: 16px;
            margin-left: 0px;

            h4 {
                font-size: 18px;
            }

            .card-panel-text {
                line-height: 18px;
                color: rgba(0, 0, 0, 0.45);
                font-size: 16px;
                margin-bottom: 12px;
            }

            .card-panel-num {
                font-size: 20px;
            }
        }
    }
}

@media (max-width: 550px) {
    .card-panel-description {
        display: none;
    }

    .card-panel-icon-wrapper {
        float: none !important;
        width: 100%;
        height: 100%;
        margin: 0 !important;

        .svg-icon {
            display: block;
            margin: 14px auto !important;
            float: none !important;
        }
    }
}
</style>
